package com.meshnetics.gb.stack.mac.type;

import com.meshnetics.gb.type.DataValue;
import com.meshnetics.gb.type.impl.ByteUtils;
import com.meshnetics.gb.type.impl.custom.ListDataType;
import com.meshnetics.gb.type.impl.zcl.TypeUInt;
import com.meshnetics.gb.type.impl.zcl.UInt;

import java.nio.ByteBuffer;

/**
 * WRITE DESCRIPTION HERE
 *
 * @author AKovylin
 */
public class TypeEnergyDetectList extends ListDataType {
    public static final TypeEnergyDetectList TYPE = new TypeEnergyDetectList();

    TypeEnergyDetectList() {
        super("energyDetectList", TypeUInt.UINT_8);
    }

    public DataValue fromObject(Object value) {
        throw new UnsupportedOperationException("not implemented yet");
        // todo reimplement
    }

    public DataValue deserialize(ByteBuffer bb) {
        throw new UnsupportedOperationException("unsupported, list length unknown");
    }

    public DataValue deserialize(ByteBuffer bb, int elemCount) {
        ByteUtils.ensureNotNull(bb);
        ByteUtils.ensureCapacity(bb, elemCount);
        UInt[] values = new UInt[elemCount];
        for (int i = 0; i < elemCount; i++) {
            values[i] = (UInt) TypeUInt.UINT_8.deserialize(bb);
        }
        return new EnergyDetectList(this, values);
    }
}
